package com.dreamlin.app

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*
import java.net.HttpURLConnection
import java.net.URL

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        assertEquals("com.dreamlin.gankotlin", appContext.packageName)
    }

    @Test
    fun contains() {
        val contains = "杜海亮".contains("杜海")
        println("contains = $contains")
    }

    @Test
    fun httpTest() {
        val url = URL("https://ae01.alicdn.com/kf/U6de089ce45ff468a8f06c50e19ad7379N.jpg")
        val conn = url.openConnection() as HttpURLConnection
        conn.requestMethod = "GET"
        conn.connectTimeout = 10000
        conn.readTimeout = 10000
        if (conn.responseCode == HttpURLConnection.HTTP_OK) {
            println(conn.contentLength)
        }
    }
}
